<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	template="/layout/template.xhtml" xmlns:a4j="http://richfaces.org/a4j">
	<ui:define name="stylefms">
		<link href="/stylesheet/theme.css" rel="stylesheet" type="text/css" />
		<link href="/stylesheet/fms.css" rel="stylesheet" type="text/css" />
		<link href="/stylesheet/panel.css" rel="stylesheet" type="text/css" />
		<link href="/stylesheet/debug.css" rel="stylesheet" type="text/css" />
	</ui:define>
	<ui:define name="varProjectName">
		<ui:param name="projectName"
			value="#{appRes['mod.fms.fms.maintenances.empleados']}" />
	</ui:define>


	<ui:define name="body">


		<a4j:form id="EmpGridForm" ajaxSingle="true">
			<rich:panel styleClass="table_back">
				<rich:datascroller align="center" for="EmpGrid" maxPages="15"
					page="#{dataTableScrollerBean.scrollerPage}"
					renderIfSinglePage="false" />

				<rich:dataTable id="EmpGrid" value="#{editEmp.allEmployees}"
					var="employee" rows="10"
					rendered="#{not empty editEmp.allEmployees}">

					<rich:column>
						<f:facet name="header">Codigo</f:facet>
						<h:outputText value="#{employee.cod}" />
					</rich:column>
					
					<rich:column>
						<f:facet name="header">Persona</f:facet>
						<h:outputText value="#{convertAssist.getPersonDescById(employee.idPerson)}" />
					</rich:column>

					<rich:column>
						<f:facet name="header">Activo</f:facet>
						<h:outputText value="#{convertAssist.booleanToString(employee.status)}" />
					</rich:column>

					<rich:column>
						<f:facet name="header">
							<h:outputText styleClass="columnHeader" value="Acciones" />
						</f:facet>
						<h:commandButton id="idCmdBorrar" value="Borrar"
							action="#{editEmp.dataToDelete(employee.id)}"
							image="/img/icons/delete_data.png"
							onclick="if (!confirm('Esta usted seguro que quiere borrar el registro ?')) return false" />
						<rich:toolTip value="Borrar" for="idCmdBorrar" />
						<rich:spacer width="20" />
						<a4j:commandLink id="editAction"  action="#{editEmp.dataToEdit(employee.id)}"
							oncomplete="#{rich:component('modalPanel')}.show()"
							reRender="modalPanel"
							immediate="true">

							<h:graphicImage id="editImg" url="/img/icons/edit.png"
								styleClass="actionsImages" />
						</a4j:commandLink>
						<rich:toolTip value="Editar" for="editAction" />
					</rich:column>

				</rich:dataTable>
			</rich:panel>

		</a4j:form>
		
		<a4j:form id="EmpForm" ajaxSingle="true">

			<rich:panel styleClass="form">
				<h:panelGrid>
					<div class="attributes">

							<s:decorate template="/layout/input.xhtml">
								<ui:define name="label">Codigo</ui:define>
								<h:inputText value="#{editEmp.employee.cod}" id="EmpCode"
									required="true" size="7"
									requiredMessage="Favor introduzca un codigo"
									validatorMessage="El codigo no puede ser menor a 3 o mayor a 5">
									<f:validateLength minimum="3" maximum="5" />
									<a4j:support event="onblur" />

								</h:inputText>
								<div class="msg_container">
								<rich:message for="EmpCode"/>
								</div>
							</s:decorate>
							<div style="clear: both;" />
																								
							<s:decorate template="/layout/input.xhtml">
								<ui:define name="label">Persona</ui:define>
							
								
								<rich:comboBox value="#{editEmp.personCod}" 
								id="EmpPerson"
								converter="#{personConverter}"
								converterMessage="Favor seleccione la persona"
								defaultLabel="Seleccione la persona"
								enableManualInput="false"
								required="true"
								requiredMessage="Favor seleccione la persona">
															
									<s:selectItems  value="#{withinHolder.personList()}" var="per" label="#{per.cod}">
									</s:selectItems>
									
								</rich:comboBox>
								<div class="msg_container">
								<rich:message for="EmpPerson"/>
								</div>
								
							</s:decorate>
							<div style="clear: both;" />
					
							<s:decorate template="/layout/input.xhtml">
								<ui:define name="label">Activo</ui:define>
								<h:selectBooleanCheckbox value="#{editEmp.employee.status}" id="EmpState"
								required="false" 
								validatorMessage="El estado no puede ser menor o mayor a 1">
								<a4j:support event="onblur" />
								</h:selectBooleanCheckbox>
								
								<div class="msg_container">
								<rich:message for="EmpState"/>
								</div>
							</s:decorate>

					</div>
	
					<s:decorate template="/layout/displayButton.xhtml"  styleClass="button_form">
						<a4j:commandButton value="Guardar"
							action="#{editEmp.saveNewData()}"
							reRender="EmpForm, EmpGridForm"
							 />
						<rich:spacer width="20px" />
						<a4j:commandButton value="Cancelar"
							action="#{editEmp.cancelData()}"
							reRender="EmpGridForm"
							onclick="if (!confirm('Esta usted seguro que desea cancelar la operacion?')) return false" />
					</s:decorate>
				</h:panelGrid>
			</rich:panel>
		</a4j:form>
		
		<rich:modalPanel  id="modalPanel" minwidth="800" minheight="300"
			resizeable="false" autosized="true" >
			<f:facet name="header">
				<h:panelGroup>
					<h:outputText value="Actualizar Empleado" />
				</h:panelGroup>
			</f:facet>
			<f:facet name="controls">
				<h:panelGroup>
					<h:graphicImage value="/img/close.png" style="cursor:pointer"
						id="hideEditApp" />
					<rich:componentControl for="modalPanel"
						attachTo="hideEditApp" operation="hide" event="onclick" />
				</h:panelGroup>
			</f:facet>
			<h:panelGroup id="idEditGroup">
			<!--  **** Include of the update page ****  -->
				<a4j:include viewId="/fms/fms/maintenances/fmsEmployeeEdit.xhtml" />
			</h:panelGroup>
		</rich:modalPanel>
	</ui:define>

</ui:composition>